<html>
<head><meta charset="utf-8"><title>issue 2799 - missing struct field diagnostics span · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.202799.20-.20missing.20struct.20field.20diagnostics.20span.html">issue 2799 - missing struct field diagnostics span</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="187250478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%202799%20-%20missing%20struct%20field%20diagnostics%20span/near/187250478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pascal <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.202799.20-.20missing.20struct.20field.20diagnostics.20span.html#187250478">(Feb 03 2020 at 10:42)</a>:</h4>
<p>Morning! If someone can point out to me how to write a test for <a href="https://github.com/rust-analyzer/rust-analyzer/issues/2799" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/issues/2799">https://github.com/rust-analyzer/rust-analyzer/issues/2799</a> I'd love to dig into it :)</p>



<a name="187250606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%202799%20-%20missing%20struct%20field%20diagnostics%20span/near/187250606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.202799.20-.20missing.20struct.20field.20diagnostics.20span.html#187250606">(Feb 03 2020 at 10:44)</a>:</h4>
<p>See <a href="https://github.com/rust-analyzer/rust-analyzer/blob/52456c44901c8c38c8bcb742ebe305484af8f36f/crates/ra_ide/src/diagnostics.rs#L536-L564" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/52456c44901c8c38c8bcb742ebe305484af8f36f/crates/ra_ide/src/diagnostics.rs#L536-L564">https://github.com/rust-analyzer/rust-analyzer/blob/52456c44901c8c38c8bcb742ebe305484af8f36f/crates/ra_ide/src/diagnostics.rs#L536-L564</a> as an example of a diagnostics test</p>



<a name="187250632"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%202799%20-%20missing%20struct%20field%20diagnostics%20span/near/187250632" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.202799.20-.20missing.20struct.20field.20diagnostics.20span.html#187250632">(Feb 03 2020 at 10:44)</a>:</h4>
<p>for the struct field diagnostic, there's an existing test <a href="https://github.com/rust-analyzer/rust-analyzer/blob/52456c44901c8c38c8bcb742ebe305484af8f36f/crates/ra_hir_ty/src/tests.rs#L294" target="_blank" title="https://github.com/rust-analyzer/rust-analyzer/blob/52456c44901c8c38c8bcb742ebe305484af8f36f/crates/ra_hir_ty/src/tests.rs#L294">here</a></p>



<a name="187250693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%202799%20-%20missing%20struct%20field%20diagnostics%20span/near/187250693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.202799.20-.20missing.20struct.20field.20diagnostics.20span.html#187250693">(Feb 03 2020 at 10:45)</a>:</h4>
<p>Yeah, actually, <span class="user-mention silent" data-user-id="129457">Florian Diebold</span> test is better, because it is more targeted</p>



<a name="187250723"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%202799%20-%20missing%20struct%20field%20diagnostics%20span/near/187250723" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.202799.20-.20missing.20struct.20field.20diagnostics.20span.html#187250723">(Feb 03 2020 at 10:45)</a>:</h4>
<p>keep in mind that you have to define everything you use, you don't get <code>vec!</code> from the standard library</p>



<a name="187250839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%202799%20-%20missing%20struct%20field%20diagnostics%20span/near/187250839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pascal <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.202799.20-.20missing.20struct.20field.20diagnostics.20span.html#187250839">(Feb 03 2020 at 10:47)</a>:</h4>
<p>thanks! i'll have a look now (instead of a lunch break :D)</p>



<a name="187251208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%202799%20-%20missing%20struct%20field%20diagnostics%20span/near/187251208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.202799.20-.20missing.20struct.20field.20diagnostics.20span.html#187251208">(Feb 03 2020 at 10:52)</a>:</h4>
<p>Hm, accutaly, I think mine proposal is a better one :D</p>
<p>Internally, the diagnostics are expressed in terms of the macro file, and it looks like what breaks here is the transition from macro-file to the original file. Ie, we show, int he original file, ranges from macro pseudo file.</p>



<a name="187251249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%202799%20-%20missing%20struct%20field%20diagnostics%20span/near/187251249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.202799.20-.20missing.20struct.20field.20diagnostics.20span.html#187251249">(Feb 03 2020 at 10:53)</a>:</h4>
<p>I think the way to fix this would be to change </p>
<div class="codehilite"><pre><span></span><span class="k">trait</span><span class="w"> </span><span class="n">Diagnostic</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">fn</span> <span class="nf">highlight_range</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">TextRange</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>to </p>
<div class="codehilite"><pre><span></span><span class="k">trait</span><span class="w"> </span><span class="n">Diagnostic</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">fn</span> <span class="nf">highlight_range</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">InFile</span><span class="o">&lt;</span><span class="n">TextRange</span><span class="o">&gt;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>and make sure that the call-site correctly unwraps potential maro file</p>



<a name="187251584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%202799%20-%20missing%20struct%20field%20diagnostics%20span/near/187251584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pascal <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.202799.20-.20missing.20struct.20field.20diagnostics.20span.html#187251584">(Feb 03 2020 at 10:57)</a>:</h4>
<p>that was my first guess as well. not sure how to change that but i'll try to understand it at least :)</p>



<a name="187251676"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%202799%20-%20missing%20struct%20field%20diagnostics%20span/near/187251676" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.202799.20-.20missing.20struct.20field.20diagnostics.20span.html#187251676">(Feb 03 2020 at 10:58)</a>:</h4>
<p>Yeah, unforutantely our internal APIs are not... polished.</p>



<a name="187251751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%202799%20-%20missing%20struct%20field%20diagnostics%20span/near/187251751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.202799.20-.20missing.20struct.20field.20diagnostics.20span.html#187251751">(Feb 03 2020 at 10:59)</a>:</h4>
<p>But the core thing to understand is that we have real files (<code>FileId</code>) and pseudo files generated by macros <code>HirFileId</code>. <code>InFile&lt;T&gt;</code> is something withing a real or pseudo file. When you render something to the user, you need to make sure that you are talking in terms of ranges in the real file.</p>



<a name="187256829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%202799%20-%20missing%20struct%20field%20diagnostics%20span/near/187256829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pascal <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.202799.20-.20missing.20struct.20field.20diagnostics.20span.html#187256829">(Feb 03 2020 at 12:24)</a>:</h4>
<p>alright, how do i resolve an <code>InFile&lt;TextRange&gt;</code> to a <code>TextRange</code> in a given <code>file_id</code>? maybe i'm looking for the wrong thing, but i hoped there was a map somewhere to translate virtual file_id ranges to spans in real files (i ask because in <code>ra_ide::Diagnostic</code> i need to set a real <code>TextRange</code>)</p>



<a name="187258954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%202799%20-%20missing%20struct%20field%20diagnostics%20span/near/187258954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.202799.20-.20missing.20struct.20field.20diagnostics.20span.html#187258954">(Feb 03 2020 at 12:56)</a>:</h4>
<p>See <code>HirFIleId::expansion_info</code></p>



<a name="187258975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/issue%202799%20-%20missing%20struct%20field%20diagnostics%20span/near/187258975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/issue.202799.20-.20missing.20struct.20field.20diagnostics.20span.html#187258975">(Feb 03 2020 at 12:56)</a>:</h4>
<p>It doesn't have API for ranges though, but it might make sense to add it.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>